<?php
namespace Customer;

use Phalcon\DiInterface;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\ModuleDefinitionInterface;

class Module implements ModuleDefinitionInterface
{
    /**
     * Registers an autoloader related to the module
     *
     * @param DiInterface $di
     */
    public function registerAutoloaders(DiInterface $di = null)
    {
        error_reporting(E_ERROR);
        $loader = new Loader();

        $loader->registerNamespaces([
            'Customer\Controllers'    => __DIR__ . '/controllers/',
            'Customer\Models'         => __DIR__ . '/models/',
            'Customer\Helpers'        => __DIR__ . '/library/Helpers/',
        ]);

        $loader->register();
    }

    /**
     * Registers services related to the module
     *
     * @param DiInterface $di
     */
    public function registerServices(DiInterface $di)
    {
        /**
         * Setting up the view component
         */
        $di->setShared('view', function (){
            $view = new View();
            $view->setViewsDir(__DIR__ . '/views/');

            $view->registerEngines([
                '.volt'  => 'voltShared',
//                '.phtml' => PhpEngine::class
            ]);

            return $view;
        });

//        $di->setShared('url', function () {
//            $config = $this->getConfig();
//
//            $url = new UrlResolver();
//
//            $url->setBaseUri($config->application->baseUri . 'customer/');
////            $url->setStaticBaseUri($config->application->baseUri . 'customer/');
//
//            return $url;
//        });

    }
}
